global root_dir = "`1'"

include "$root_dir/code/config/config.do"

cap noi log using ${log_dir}/figure_A11_shocklevel_binscatter.log, replace name(fig)

capture noi {

    * BHJ shocklevel binscatter

    qui include ${code_dir}/config/figuretools.do

    use ${final_dir}/regression_dataset_from1970_tfacit1_countrylevel_resid, clear

    local depvar arcsinh_auto95_bia
    local indepvar ISP
    local v _fiycy

    *define text of coefficients to be displayed
    reg r`depvar'`v' r`indepvar'`v' [aw = s_n], cluster(country_id)
    local coef : di %3.2f _b[r`indepvar'`v']
    local se : di %3.2f _se[r`indepvar'`v']

    *set graphing parameters
    colorpalette ptol, n(2) nograph
    local clr1: di "`r(p1)'"
    local clr2: di "`r(p2)'"

    di "`clr1'"
    colorpalette ptol, n(2) nograph
    binscatter r`depvar'`v' r`indepvar'`v' [aw = s_n], nquant(100) reportreg ///
    linetype(lfit) lcolor(gs4) mcolor(gs8) msymb(circle_hollow) ///
    ytitle("Arcsinh Auto95 (residualized)") xtitle("Inverse Skill Premium (residualized)") ///
    text(-0.015 0.015 "Coef = `coef'" "(`se')", just(right)) 
    graph export ${fig_dir}/appendix/Figure_A11_shocklevel_binscatter.pdf, replace
    graph export ${fig_dir}/appendix/Figure_A11_shocklevel_binscatter.eps, replace
}
if _rc == 0 {
    display "Execution finished successfully."
}
else {
    display "Execution finished with errors."
}

cap log close fig